package com.example.peibei.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.dingtao.common.core.WDActivity;
import com.example.peibei.R;
import com.tencent.imsdk.v2.V2TIMConversation;
import com.tencent.qcloud.tuicore.TUIConstants;
import com.tencent.qcloud.tuicore.TUICore;
import com.tencent.qcloud.tuikit.tuicontact.bean.ContactItemBean;
import com.tencent.qcloud.tuikit.tuicontact.util.ContactUtils;
import com.tencent.qcloud.tuikit.tuiconversation.bean.ConversationInfo;

import butterknife.BindView;
import butterknife.OnClick;

public class SendOrderDetailActivity extends WDActivity {
    @BindView(R.id.ll_chat)
    LinearLayout ll_chat;

    private String consumeOrderId;
    private String mid;
    private String nickName;
    private int status;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_send_order_detail;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        consumeOrderId = bundle.getString("consumeOrderId");
        mid = bundle.getString("userId");
        nickName = bundle.getString("nickName");
        status = bundle.getInt("status");
    }

    @OnClick(R.id.iv_back)
    public void back(){finish();}

    @OnClick(R.id.ll_chat)
    public void chat(){
        ConversationInfo conversationInfo = new ConversationInfo();
        conversationInfo.setType(ConversationInfo.TYPE_CUSTOM);
        conversationInfo.setId(mid);
        conversationInfo.setGroup(false);
        conversationInfo.setTitle(nickName);
        startChatActivity(conversationInfo);

//        ContactUtils.startChatActivity(mid, ContactItemBean.TYPE_C2C, "nickname", "");
    }

    private void startChatActivity(ConversationInfo conversationInfo) {
        Bundle param = new Bundle();
        param.putInt(TUIConstants.TUIChat.CHAT_TYPE, conversationInfo.isGroup() ? V2TIMConversation.V2TIM_GROUP : V2TIMConversation.V2TIM_C2C);
        param.putString(TUIConstants.TUIChat.CHAT_ID, conversationInfo.getId());
        param.putString(TUIConstants.TUIChat.CHAT_NAME, conversationInfo.getTitle());
        if (conversationInfo.getDraft() != null) {
            param.putString(TUIConstants.TUIChat.DRAFT_TEXT, conversationInfo.getDraft().getDraftText());
            param.putLong(TUIConstants.TUIChat.DRAFT_TIME, conversationInfo.getDraft().getDraftTime());
        }
        param.putBoolean(TUIConstants.TUIChat.IS_TOP_CHAT, conversationInfo.isTop());

        if (conversationInfo.isGroup()) {
            param.putString(TUIConstants.TUIChat.FACE_URL, conversationInfo.getIconPath());
            param.putString(TUIConstants.TUIChat.GROUP_TYPE, conversationInfo.getGroupType());
        }
        if (conversationInfo.isGroup()) {
            TUICore.startActivity(TUIConstants.TUIChat.GROUP_CHAT_ACTIVITY_NAME, param);
        } else {
            TUICore.startActivity(TUIConstants.TUIChat.C2C_CHAT_ACTIVITY_NAME, param);
        }
    }

    @Override
    protected void destoryData() {

    }
}
